<template>
  <div>
    <a-row type="flex" class="condition-top">
      <div class="condition-top-item" style="background: none;
      border: 0;">您已选择：</div>
      <div v-for="(item,index) in conditionTop" :key="index">
        <div class="condition-top-item" v-if="item.id">
          {{item.type}}:&nbsp;{{item.name}}&nbsp;&nbsp;
          <a-icon type="close" style="color:#0084ff;  cursor: pointer;" @click="close(item.type)" />
        </div>
      </div>
    </a-row>
    <div class="condition-bottom" v-if="conditionTopSoft">
      <div v-for="(item,index) in arrConditionZB" :key="index">
        <a-row type="flex" class="condition-bottom-row">
          <a-col :span="2">{{item.type}}:</a-col>
          <a-col
            :span="3"
            v-for="(itemChild,indexChild) in item.list"
            :key="indexChild"
            class="ritem"
            @click.stop="itemTag(itemChild,item.type)"
          >{{itemChild.name}}</a-col>
        </a-row>
      </div>
    </div>
    <div class="condition-bottom" v-else>
      <div v-for="(item,index) in arrCondition" :key="index">
        <a-row
          type="flex"
          class="condition-bottom-row"
          v-if="item.list.length>0 && !conditionTop[index+1].id"
        >
          <a-col :span="2">{{item.type}}:</a-col>
          <a-col :span="22">
            <a-col
              :span="3"
              v-for="(itemChild,indexChild) in item.list"
              :key="indexChild"
              class="ritem"
              @click.stop="itemTag(itemChild,item.type)"
            >{{itemChild.name}}</a-col>
            <a-col :span="8" v-if="item.type == '价格区间'">
              <a-col :span="16" style="margin-top:6px;">
                <a-input-group size="small" compact>
                  <a-input-number size="small" style=" width: 100px;" v-model="pr1" :max="pr2" />
                  <a-input
                    style=" width: 30px; border-left: 0; pointer-events: none; backgroundColor: #fff"
                    placeholder="~"
                    disabled
                  />
                  <a-input-number
                    size="small"
                    style="width: 100px; border-left: 0"
                    v-model="pr2"
                    :min="pr1"
                  />
                </a-input-group>
              </a-col>
              <a-col :span="6">
                <a-button size="small" @click="prTag">确定</a-button>
              </a-col>
            </a-col>
          </a-col>
        </a-row>
      </div>
    </div>
    <lineChart v-if="conditionTop[0].name === '游戏币'" :list_id="list_id" />
    <a-row type="flex" class="sort">
      <div @click="sortTag">
        时间排序
        <a-icon v-if="sort" type="down" />
        <a-icon v-else type="up" />
      </div>
    </a-row>
    <a-row type="flex" class="list">
      <a-col :span="24" class="list-h">
        <a-col :span="9">商品标题</a-col>
        <a-col :span="5">卖家</a-col>
        <a-col :span="5">价格</a-col>
        <a-col :span="5">商品更新时间</a-col>
      </a-col>
      <a-col
        :span="24"
        class="list-box cp"
        v-for="(item,index) in list"
        :key="index"
        @click="onJump(item)"
      >
        <a-col :span="9">
          <a-col :span="5">
            <img :src="item.icon" alt srcset />
          </a-col>
          <a-col :span="18" class="list-box-n" style=" text-align: left;">
            <div class="list-box-n-tit">{{item.title}}</div>
            <div>商品类型：{{item.cate}}</div>
            <div>{{item.wow}}{{item.twow}}</div>
          </a-col>
        </a-col>
        <a-col :span="5" class="list-box-f">
          <div>{{item.name}}</div>
          <div>{{item.set_member}}</div>
        </a-col>
        <a-col :span="5">
          <div class="list-box-m">￥{{item.price}}</div>
          <!-- <div class="list-box-f">当前均价</div> -->
        </a-col>
        <a-col :span="5">
          <div class="list-box-f">{{item.create_time}}</div>
        </a-col>
      </a-col>
    </a-row>
    <div class="pagination">
      <a-pagination showQuickonJumper v-model="page" :total="total" @change="onChange" />
    </div>
  </div>
</template>

<script>
import { GAT_CATE, GAT_WOW, SHOP_LIST, GET_LIST_WOW } from "../server";
export default {
  layout: "main",
  components: {
    lineChart: () => import("~/components/other/lineChart")
  },
  data() {
    return {
      contents: "游戏列表list" + this.$route.params.list,
      routers: {},
      list: [],
      arrConditionZB: [
        {
          type: "商品类型",
          list: []
        }
      ],
      arrCondition: [
        {
          type: "游戏区",
          list: []
        },
        {
          type: "游戏服",
          list: []
        },
        {
          type: "价格区间",
          list: [
            { name: "100元以下", price1: 0, price2: 100 },
            { name: "100到200元", price1: 100, price2: 200 },
            { name: "201到500元", price1: 201, price2: 500 },
            { name: "501到1000元", price1: 501, price2: 1000 },
            { name: "1000元以上", price1: 1000, price2: 99999999999 }
          ]
        }
      ],
      conditionTop: [
        { type: "商品类型", id: "", name: "" },
        { type: "游戏区", id: "", name: "" },
        { type: "游戏服", id: "", name: "" },
        { type: "价格区间", id: "", name: "" }
      ],
      sort: true,
      sortNum: 2,
      conditionTopSoft: true,
      pr1: 0,
      pr2: 0,
      page: 1,
      total: 0,
      search: "",
      list_id: ''
    };
  },
  created() {
    // console.log(this.$route.params, 174)
    this.list_id = this.$route.params.list
    this.default();
    this.getWow();
    this.getShop();
    // this.getListWow()
  },
  methods: {
    onJump(v) {
      this.$router.push({
        name: `game-list-msg`,
        params: {
          msg: v.game_id
        }
      });
    },
    itemTag(item, n) {
      let id;
      let name;
      switch (n) {
        case "商品类型":
          this.conditionTopSoft = false;
          id = item.cate_id;
          break;
        case "游戏区":
          id = item.wow_de_id;
          this.arrCondition[1].list = item.two || [];
          break;
        case "游戏服":
          id = item.wow_de_id;
          break;
        case "价格区间":
          id = [item.price1, item.price2];
          break;
      }
      this.conditionTop.some(ele => {
        if (ele.type == n) {
          ele.id = id;
          ele.name = item.name;
          return true;
        }
      });
      this.getShop();
    },
    close(n) {
      if (n === "商品类型") {
        this.conditionTopSoft = true;
        this.getCate();
        this.conditionTop = [
          { type: "商品类型", id: "", name: "" },
          { type: "游戏区", id: "", name: "" },
          { type: "游戏服", id: "", name: "" },
          { type: "价格区间", id: "", name: "" }
        ];
      } else if (n === "游戏区") {
        this.conditionTop[1].id = "";
        this.conditionTop[1].name = "";
        this.conditionTop[2].id = "";
        this.conditionTop[2].name = "";
        this.arrCondition[1].list = [];
      } else {
        this.conditionTop.some(ele => {
          if (ele.type == n) {
            ele.id = "";
            ele.name = "";
            return true;
          }
        });
      }
      this.getShop();
    },
    prTag() {
      this.conditionTop[3].id = [this.pr1, this.pr2];
      this.conditionTop[3].name = this.pr1 + "到" + this.pr2;
      this.getShop();
    },
    sortTag() {
      this.sort = !this.sort;
    },
    getWow() {
      GAT_WOW({ list_id: this.$route.params.list }).then(res => {
        if (!res) return;
        this.arrCondition[0].list = res.data;
      });
    },
    // getListWow() {
    //   GET_LIST_WOW({
    //     list_id: this.$route.params.list
    //   }).then(res => {
    //     this.yxbId = res.data[0].wow_de_id
    //   })
    // },
    getCate() {
      GAT_CATE({ list_id: this.$route.params.list, lv: 1 }).then(res => {
        if (!res) return;
        this.arrConditionZB[0].list = res.data;
      });
    },
    onChange(page) {
      this.page = page;
      this.getShop();
    },
    getShop(sort = 3) {
      SHOP_LIST({
        page: this.page,
        pageshow: 10,
        list_id: this.$route.params.list,
        cate: this.conditionTop[0].id,
        wow: this.conditionTop[2].id || this.conditionTop[1].id,
        price1: this.conditionTop[3].id[0],
        price2: this.conditionTop[3].id[1],
        sort: this.sortNum
      }).then(res => {
        if (res) {
          this.list = res.data.list;
          this.total = res.data.count;
        } else {
          this.list = [];
          this.total = 0;
        }
      });
    },
    default(V) {
      if (this.$route.params.type == "search") {
        let {
          cate_id,
          cate_name,
          wow_id,
          wow_name,
          twow_id,
          twow_name,
          search
        } = this.$route.params;
        if (cate_id) {
          this.conditionTopSoft = false;
          this.conditionTop[0].id = cate_id;
          this.conditionTop[0].name = cate_name;
          this.conditionTop[1].id = wow_id;
          this.conditionTop[1].name = wow_name;
          this.conditionTop[2].id = twow_id;
          this.conditionTop[2].name = twow_name;
        } else {
          this.getCate();
        }
        this.search = search;
      } else if (
        this.$route.params.type == "game" &&
        this.$route.params.cate_name
      ) {
        this.conditionTopSoft = false;
        let { cate_name, cate_id } = this.$route.params;
        this.conditionTop[0].name = cate_name;
        this.conditionTop[0].id = cate_id;
      } else {
        this.getCate();
      }
    },
    current() {
      let {
        cate_id,
        cate_name,
        wow_id,
        wow_name,
        twow_id,
        twow_name,
        search
      } = this.$store.state.arrNav;
      if (cate_id) {
        this.conditionTopSoft = false;
        this.conditionTop[0].id = cate_id;
        this.conditionTop[0].name = cate_name;
        this.conditionTop[1].id = wow_id;
        this.conditionTop[1].name = wow_name;
        this.conditionTop[2].id = twow_id;
        this.conditionTop[2].name = twow_name;
        this.arrCondition[0].list.some(ele => {
          if (ele.wow_de_id == wow_id) {
            this.arrCondition[1].list = ele.two || [];
          }
        });
      } else {
        this.getCate();
      }
      this.search = search;
    }
  },
  computed: {
    arrNavNum() {
      return this.$store.state.arrNavNum;
    }
  },
  watch: {
    sort(v) {
      if (v) {
        this.sortNum = 2;
      } else {
        this.sortNum = 3;
      }
      this.getShop();
    },
    arrNavNum(v) {
      this.current();
    }
  }
};
</script>
<style lang="less" scoped>
.condition-top {
  min-height: 40px;
  // line-height: 40px;
  background: #f6f6f6;
  border: 1px solid #e8e8e8;
  padding: 0 20px;
  .condition-top-item {
    display: inline-block;
    height: 26px;
    line-height: 26px;
    margin-top: 6px;
    padding: 0 6px;
    background: #fff;
    border: 1px solid #ededed;
    margin-right: 10px;
  }
}
.condition-bottom {
  border: 1px solid #e8e8e8;
  border-top: 0;
  padding: 0 20px;
  .condition-bottom-row {
    min-height: 36px;
    line-height: 36px;
    border-bottom: 1px dashed #e8e8e8;
    .ritem {
      cursor: pointer;
      &:hover {
        color: #0084ff;
      }
    }
  }
  &:last-child .condition-bottom-row {
    border: 0;
  }
}

.sort {
  border: 1px solid #e8e8e8;
  height: 44px;
  line-height: 44px;
  margin-top: 10px;
  div {
    cursor: pointer;
    padding: 0 12px;
  }
}
.list {
  margin-bottom: 46px;
  border-bottom: 1px solid #e8e8e8;
  font-size: 12px;
  .list-h {
    height: 36px;
    line-height: 36px;
    border-bottom: 1px solid #e8e8e8;
    text-align: center;
  }
  .list-box {
    height: 116px;
    padding: 16px 0;
    border-bottom: 1px solid #e8e8e8;
    text-align: center;
    img {
      width: 90px;
      height: 90px;
    }
    .list-box-n {
      margin-left: 16px;
      .list-box-n-tit {
        height: 46px;
        font-weight: bold;
        font-size: 14px;
        overflow: hidden;
        display: -webkit-box;
        text-overflow: ellipsis;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
      }
    }
    .list-box-f {
      color: #999;
    }
    .list-box-m {
      color: #0084ff;
      font-size: 18px;
      font-weight: bold;
    }
    .list-box-c {
      display: inline-block;
      width: 20px;
      height: 20px;
      line-height: 20px;
      text-align: center;
      background: red;
      border-radius: 5px;
      color: #fff;
      margin-right: 4px;
      margin-bottom: 4px;
    }
  }
}
.pagination {
  margin: 100px auto;
  text-align: center;
}
</style>